package com.ruoyi.robot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.robot.domain.UserChatData;
import com.ruoyi.robot.service.IUserChatDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机器人对话历史记录Controller
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/robot/chat")
public class UserChatDataController extends BaseController
{
    @Autowired
    private IUserChatDataService userChatDataService;

    UserChatData userChatData = new UserChatData();

    //获取对话历史记录
    @GetMapping("/getChatHistory")
    @ResponseBody
    public TableDataInfo getChatHistory(@RequestParam("nameId") String nameId, @RequestParam("toId") String toId)
    {

        //按发送用户ID、接收用户ID查询、分页
        userChatData.setNameId(nameId);
        userChatData.setToId(toId);
        startPage();
        List<UserChatData> list = userChatDataService.getHistoryChatList(userChatData);
        return getDataTable(list);
    }
    /**
     * 查询机器人对话历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('robot:chat:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserChatData userChatData)
    {
        startPage();
        List<UserChatData> list = userChatDataService.selectUserChatDataList(userChatData);
        return getDataTable(list);
    }

    /**
     * 导出机器人对话历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('robot:chat:export')")
    @Log(title = "机器人对话历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserChatData userChatData)
    {
        List<UserChatData> list = userChatDataService.selectUserChatDataList(userChatData);
        ExcelUtil<UserChatData> util = new ExcelUtil<UserChatData>(UserChatData.class);
        util.exportExcel(response, list, "机器人对话历史记录数据");
    }

    /**
     * 获取机器人对话历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('robot:chat:query')")
    @GetMapping(value = "/{name}")
    public AjaxResult getInfo(@PathVariable("name") String name)
    {
        return success(userChatDataService.selectUserChatDataByName(name));
    }

    /**
     * 新增机器人对话历史记录
     */
    @PreAuthorize("@ss.hasPermi('robot:chat:add')")
    @Log(title = "机器人对话历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserChatData userChatData)
    {
        return toAjax(userChatDataService.insertUserChatData(userChatData));
    }

    /**
     * 修改机器人对话历史记录
     */
    @PreAuthorize("@ss.hasPermi('robot:chat:edit')")
    @Log(title = "机器人对话历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserChatData userChatData)
    {
        return toAjax(userChatDataService.updateUserChatData(userChatData));
    }

    /**
     * 删除机器人对话历史记录
     */
    @PreAuthorize("@ss.hasPermi('robot:chat:remove')")
    @Log(title = "机器人对话历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{names}")
    public AjaxResult remove(@PathVariable String[] names)
    {
        return toAjax(userChatDataService.deleteUserChatDataByNames(names));
    }
}
